/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ControlGUI.java
 *
 * Created on Apr 8, 2012, 12:37:18 PM
 */
package Control;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.*;
import java.util.ArrayList;
import javax.swing.JPanel;

/**
 *
 * @author Eng Omnia
 */
public class ControlGUI extends javax.swing.JFrame {

    /**
     * Creates new form ControlGUI
     */
    public ControlGUI() {

        initComponents();
        MouseListener m = new MyMouseListener();
        jPanel1.addMouseListener(m);
        AL keyListener = new AL();
        jTextField1.addKeyListener(keyListener);
        jPanel1.addKeyListener(keyListener);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new PaintSurface();
        jSeparator1 = new javax.swing.JSeparator();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ControlPics/node.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ControlPics/curve2.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ControlPics/done.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 18));
        jLabel1.setText("Write Node Name >>");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jSeparator1.setBackground(new java.awt.Color(0, 0, 0));

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ControlPics/select.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ControlPics/delete.png"))); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(104, 104, 104)
                        .addComponent(jButton5)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 844, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 870, Short.MAX_VALUE))))
                .addContainerGap(124, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(20, 20, 20)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton3)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton2)
                                .addComponent(jButton1)
                                .addComponent(jButton4)
                                .addComponent(jButton5)))
                        .addGap(27, 27, 27))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 37, Short.MAX_VALUE))))
        );

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        methodType = 2;
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        methodType = 1;
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

select=true;
        methodType = 3;
        jTextField1.requestFocusInWindow();

    }                                        

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }                                           

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        delete();
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your h.andling code here:
        ArrayList<MyObject> answer = new ArrayList<MyObject>();
        for (int i = 0; i < relations.size(); i++) {
            Relations r = relations.get(i);
            char first = nodes[r.getFirstNodeIndex()].getName().charAt(0);
            char last = nodes[r.getSecondNodeIndex()].getName().charAt(0);
            String gain = lines[r.getArrowIndex()].getEquation();
            MyObject m = new MyObject(first, last, gain);
            answer.add(m);
        }
        for (int i = 0; i < answer.size(); i++) {
            System.out.println(i);
            System.out.println("first" + answer.get(i).getFirst() + "Second" + answer.get(i).getLast() + "gain" + answer.get(i).getGain());
        }
    }                                        
    private Point2D getPointOfIntersection(Ellipse2D node, int intersect) {
        Point2D pointOfIntersect = new Point2D.Double();
        double x = 0;
        double y = 0;
        if (intersect == 1) {
            // the most top point
            x = node.getCenterX();
            y = node.getCenterY() - (node.getHeight() / 2);

        } else if (intersect == 2) {
            // the most right point
            x = node.getCenterX() + (node.getWidth() / 2);
            y = node.getCenterY();
        } else if (intersect == 3) {
            // the most bottom point
            x = node.getCenterX();
            y = node.getCenterY() + (node.getHeight() / 2);
        } else {
            // intersect ==4
            // the most left point
            x = node.getCenterX() - (node.getWidth() / 2);
            y = node.getCenterY();
        }
        pointOfIntersect.setLocation(x, y);
        return pointOfIntersect;
    }

    private void deleteRelation() {
        int i = 0;
        while (i < relations.size()) {
            Relations curr = relations.get(i);
            if (typeSelected == 1) {
                if (curr.getArrowIndex() == indexSelected) {
                    relations.remove(i);
                } else {
                    i++;
                }
            } else {
                if (curr.getFirstNodeIndex() == indexSelected || curr.getSecondNodeIndex() == indexSelected) {
                    int deleteArrow = curr.getArrowIndex();
                    System.out.print(deleteArrow);
                    lines[deleteArrow] = null;
                    relations.remove(i);
                } else {
                    i++;
                }
            }
        }

    }

    private void select(Point2D curr) {
        ArrayList<Integer> array = new ArrayList<Integer>();
        int index = -1;
        int type = -1;
        boolean check = true;
        for (int i = 0; i < lines.length; i++) {
            if (lines[i] != null) {
                if (lines[i].contains(curr)) {
                    index = i;
                    type = 1;
                    check = false;
                }
            }
        }
        if (check) {
            for (int i = 0; i < nodes.length; i++) {
                if (nodes[i] != null) {
                    if (nodes[i].contains(curr)) {
                        index = i;
                        type = 2;
                    }
                }
            }
        }

        indexSelected = index;
        typeSelected = type;
    }

    private ArrayList<Point2D> createBranch(Point2D p1, Point2D p2) {
        Ellipse2D.Double firstNode = null;
        Ellipse2D.Double secondNode = null;
        int firstNodeIndex = 0;
        int secondNodeIndex = 0;
        int arrowIndex = 0;
        int theta = 30;
        for (int i = 0; i < nodes.length; i++) {
            if (nodes[i] != null) {
                Ellipse2D.Double curr = (Ellipse2D.Double) nodes[i].getMyShape();
//			System.out.println(i);
//			System.out.println("p1 data"+p1.getX()+"    "+p1.getY());
//			System.out.println("p2 data"+p2.getX()+"   "+p2.getY());
//			System.out.println(" circle"+curr.getCenterX()+"    "+curr.getCenterY());
//			
                if (curr.contains(p1)) {
                    firstNode = curr;
                    firstNodeIndex = i;
                }
                if (curr.contains(p2)) {
                    secondNode = curr;
                    secondNodeIndex = i;
                }
            }
        }
        int type = getType(p1, p2);

        Point2D point1 = new Point2D.Double();
        Point2D point2 = new Point2D.Double();
        Point2D point3 = new Point2D.Double();

        point1 = getPointOfIntersection(firstNode, type);
        point2 = getPointOfIntersection(secondNode, type);
        point3 = creatThirdPoint(point1, point2, type);
        if (firstNodeIndex == secondNodeIndex) {
            point1 = getPointOfIntersection(firstNode, 1);
            point2 = getPointOfIntersection(secondNode, 4);
            // Point2D p22 = new Point2D.Double(point2.getX()-100,point2.getY());
            point3 = creatThirdPoint(point1, point2, type);
        }
        ArrayList<Point2D> array = new ArrayList<Point2D>();
        array.add(point1);
        array.add(point2);
        array.add(point3);
        Point2D p4 = new Point2D.Double(firstNodeIndex, secondNodeIndex);
        array.add(p4);
        return array;
    }

    private int getType(Point2D p1, Point2D p2) {

        int type = 0;
        int type2 = 0;
        double p1X = p1.getX();
        double p2X = p2.getX();
        double p1Y = p1.getY();
        double p2Y = p2.getY();
        if (p2X > p1X) {
            type = 1;
        } else {
            type = 3;
        }
        if (p2Y > p1Y) {
            type2 = 2;
        } else {
            type2 = 4;
        }
        if (type == 1 && type2 == 2) {
            if (p2X - p1X > p2Y - p1Y) {
                type = 1;
            } else {
                type = 2;
            }
        } else if (type == 1 && type == 4) {
            if (p2X - p1X > p1Y - p2Y) {
                type = 1;
            } else {
                type = 4;
            }
        } else if (type == 3 && type2 == 2) {
            if (p1X - p2X > p2Y - p1Y) {
                type = 3;
            } else {
                type = 2;
            }
        } else {
            if (p1X - p2X > p1Y - p2Y) {
                type = 3;
            } else {
                type = 4;
            }
        }
        return type;
    }

    private Point2D creatThirdPoint(Point2D p1, Point2D p2, int type) {
        double x = 0;
        double y = 0;
        double x1 = p1.getX();
        double x2 = p2.getX();
        double y1 = p1.getY();
        double y2 = p2.getY();
        if (type == 1) {
            x = (x1 + x2) / 2;
            y = y1 - epsilonY;
        } else if (type == 3) {
            x = (x1 + x2) / 2;
            y = y1 + epsilonY;
        } else if (type == 2) {
            x = x1 + epsilonY;
            y = (y1 + y2) / 2;
        } else if (type == 4) {
            x = x1 - epsilonY;
            y = (y1 + y2) / 2;
        }
        Point2D p = new Point2D.Double(x, y);
        return p;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ControlGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ControlGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ControlGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ControlGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ControlGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private java.awt.Canvas jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration
    private Arrows[] lines = new Arrows[1000];
    private ShapeObject[] nodes = new ShapeObject[1000];
    private ArrayList<Relations> relations = new ArrayList<Relations>();
    int epsilonY = 30;
    Point2D firstP;
    Point2D secondP;
    double x1 = 0;
    double x2 = 0;
    double y1 = 0;
    double y2 = 0;
    int methodType = 0;
    int xCircle = 0;
    int yCircle = 0;
    int barb = 20;
    double phi = Math.PI / 6;
    int indexSelected = -1;
    int typeSelected = -1;
    boolean delete = false;
    int linesCount = 0;
    int nodeCount;
    boolean select = false;

    class PaintSurface extends Canvas {

        public PaintSurface() {
            // setForeground(new java.awt.Color(204, 204, 204));
        }

        public void paint(Graphics g) {

            //    System.out.print("here");
            Graphics2D g2D = (Graphics2D) g;

            for (int i = 0; i < lines.length; i++) {
                //              System.out.println(i);
//                System.out.println(lines.get(i).getBounds());
                if (lines[i] != null) {
                    Arrows curr = lines[i];
                    g2D.draw(curr.getCurve());
                    g2D.draw(curr.getFirstArrow());
                    g2D.draw(curr.getSecondArrow());
                   
                   if(select){
                        Rectangle2D.Double v = (Rectangle2D.Double) curr.getCurve().getBounds2D();
                    Rectangle2D.Double v2 = new Rectangle2D.Double(v.getCenterX(), v.getCenterY(), 5, 5);
                    g2D.draw(v2);

                    g2D.fill(v2);
                   }
                    g2D.drawString(curr.getEquation(), (int) curr.getCurve().getBounds().getCenterX(), (int) curr.getCurve().getBounds().getCenterY());
                }
            }
            for (int i = 0; i < nodes.length; i++) {
                if (nodes[i] != null) {
                    ShapeObject curr = nodes[i];
                    g2D.draw(curr.getMyShape());
                    
                    if(select){
                        Ellipse2D e = new Ellipse2D.Double((int)curr.getMyShape().getBounds().getCenterX()-5,(int)curr.getMyShape().getBounds().getCenterY(),5,5);
                        g2D.draw(e);
                        g2D.fill(e);
                    }
                    //g2D.fill(nodes.get(i));
                    g2D.drawString(curr.getName(), (int) (curr.getMyShape().getBounds2D().getCenterX()), (int) (curr.getMyShape().getBounds2D().getCenterY() - curr.getMyShape().getBounds().getHeight()));
                }
            }

        }
    }

    class MyMouseListener extends MouseAdapter implements MouseMotionListener {

        // private QuadCurve2D.Double myCurve = new QuadCurve2D.Double();
        private int press = 0;

        public void mousePressed(MouseEvent e) {
            //System.out.println("no Of press" + press);
            if (methodType == 1) {
                select = false;
                indexSelected = -1;

                if (press == 0) {
                    //  x1 = e.getX();
                    //  y1 = e.getY();
                    //   QuadCurve2D.Double myCurve = new QuadCurve2D.Double();
                    press = 1;
                    firstP = e.getPoint();
                } else {
                    secondP = e.getPoint();
                    x2 = e.getX();
                    y2 = e.getY();
                    ArrayList<Point2D> points = createBranch(firstP, secondP);
                    Point2D p1 = points.get(0);
                    Point2D p2 = points.get(1);
                    Point2D p3 = points.get(2);
                    QuadCurve2D.Double myCurve = new QuadCurve2D.Double();
                    myCurve.setCurve(p1.getX(), p1.getY(), p3.getX(),
                            p3.getY(), p2.getX(), p2.getY());
                    // myCurve.setCurve(40, 150, 80, 180, 140, 150);
                    //lines.add((Shape) myCurve.clone());
                    Arrows curve = new Arrows();
                    //index of the curve
                    curve.setIndex(linesCount);

                    curve.setCurve((Shape) myCurve.clone());
                    // System.out.println("x1  " + x1);
                    // System.out.println("y1  " + y1);
                    // System.out.println("x2  " + x2);
                    // System.out.println("y2  " + y2);
                    double theta = Math.atan2(p2.getY() - p3.getY(), p2.getX() - p3.getX());
                    double xtemp = p2.getX() - barb * Math.cos(theta + phi);
                    double ytemp = p2.getY() - barb * Math.sin(theta + phi);
                    Line2D.Double l = new java.awt.geom.Line2D.Double();
                    l.setLine(p2.getX(), p2.getY(), xtemp, ytemp);
//                    lines.add(l);
                    curve.setFirstArrow(l);
                    curve.setPeek(p3);
//     					g2.draw(new Line2D.Double(x2, y2, xtemp, ytemp));
                    xtemp = p2.getX() - barb * Math.cos(theta - phi);
                    ytemp = p2.getY() - barb * Math.sin(theta - phi);
                    Line2D.Double l2 = new java.awt.geom.Line2D.Double();
                    l2.setLine(p2.getX(), p2.getY(), xtemp, ytemp);

                    //                lines.add(l2);
                    curve.setSecondArrow(l2);
                    lines[linesCount] = curve;
                    linesCount++;
                    Relations r = new Relations();
                    r.setArrowIndex(linesCount - 1);
                    Point2D.Double p4 = (Point2D.Double) points.get(3);

                    r.setFirstNodeIndex((int) p4.getX());
                    r.setSecondNodeIndex((int) p4.getY());
                    relations.add(r);
                    press = 0;
                    System.out.print("count" + linesCount);
                    //    methodType = 0;
                }
            } else if (methodType == 2) {
                select = false;
                indexSelected = -1;
                xCircle = e.getX();
                yCircle = e.getY();
                Ellipse2D.Double ellipse = new Ellipse2D.Double();
                //			
                ellipse.setFrame(xCircle - 10, yCircle - 10, 20, 20);

//     				System.out.println("ellipse  " + xCircle);
//     				System.out.println("ellipse " + yCircle);
                ShapeObject myEllipse = new ShapeObject(ellipse, nodeCount);
                if (methodType == 2) {
                    nodes[nodeCount] = myEllipse;
                }
                nodeCount++;

                // centers.add(new Point(e.getX(), e.getY()));
                //    methodType = 0;

            } else if (methodType == 3) {
                select = true;
                Point2D curr = e.getPoint();
                select(curr);

                jTextField1.requestFocusInWindow();
            } else {
                press = 0;
                select = false;
            }
            repaint();
            jPanel1.repaint();

        }
    }

    private void delete() {
        if (indexSelected == -1) {
            return;
        }
        if (typeSelected == 1) {
            lines[indexSelected] = null;
            deleteRelation();
            jPanel1.repaint();
        } else if (typeSelected == 2) {
            nodes[indexSelected] = null;
            deleteRelation();
            jPanel1.repaint();
        } else {
            return;
        }


    }

    private class AL extends KeyAdapter {

        public void keyPressed(KeyEvent e) {
            //throw new UnsupportedOperationException("Not supported yet.");

            if (e.getKeyCode() == KeyEvent.VK_ENTER) {

                if (indexSelected == -1) {
                    return;
                }
                if (typeSelected == 1) {
                    Arrows curr = lines[indexSelected];
                    curr.setEquation(jTextField1.getText());
                    jPanel1.repaint();
                } else if (typeSelected == 2) {
                    ShapeObject curr = nodes[indexSelected];
                    curr.setName(jTextField1.getText().charAt(0) + "");
                    jPanel1.repaint();
                } else {
                    return;
                }
            } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                System.out.print("delete");
                delete();
            }


        }
    }
}
